package com.jic.product.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.product.entity.CategoryManagement;
import com.jic.product.mapper.CategoryManagementMapper;
import com.jic.product.manage.request.CategoryManagementRequest;
import com.jic.product.manage.response.CategoryManagementResponse;
import com.jic.product.service.CategoryManagementService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商家类目资质管理
 * @author :
 * @email :
 * @since : 2020-01-10 07:03:01
 * @version : v1.0.0
 */
@Service
public class CategoryManagementServiceImpl implements CategoryManagementService{

    @Autowired
    private CategoryManagementMapper categoryManagementMapper;

    @Override
    public long insert(CategoryManagementRequest categoryManagement) {
        long flag = categoryManagementMapper.insert(categoryManagement);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return categoryManagementMapper.delete(id);
    }

    @Override
    public long update(CategoryManagementRequest categoryManagement) {
        return categoryManagementMapper.update(categoryManagement);
    }

    @Override
    public CategoryManagement queryByPrimaryKey(Long id){
        return categoryManagementMapper.queryByPrimaryKey(id);
    }

    @Override
    public PageResult<CategoryManagementResponse> query(CategoryManagementRequest categoryManagement){
        List<CategoryManagementResponse> list = categoryManagementMapper.query(categoryManagement);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(0);
        return pageResult;
    }

    @Override
    public PageResult<CategoryManagementResponse> queryPage(CategoryManagementRequest categoryManagement, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CategoryManagementResponse> list = categoryManagementMapper.queryPage(startIndex, pageQuery.getLimit(), categoryManagement);
        long count = categoryManagementMapper.queryPageCount(categoryManagement);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public RestResult<CategoryManagementResponse> queryInfo(CategoryManagementRequest category) {
        RestResult restResult=new RestResult();
        CategoryManagementResponse list = categoryManagementMapper.queryInfo(category);
        restResult.setData(list);
        return restResult;
    }

}
